export function selectClientRect(this: any, selector: string, _this?: any) {
  return new Promise<UniApp.NodeInfo | UniApp.NodeInfo[]>((resolve, reject) => {
    uni
      .createSelectorQuery()
      .in(_this || (this as any))
      .select(selector)
      .boundingClientRect((result) =>
        result ? resolve(result) : reject(result)
      )
      .exec()
  })
}

export function selectNode(this: any, selector: string, _this?: any) {
  return new Promise<any>((resolve, reject) => {
    uni
      .createSelectorQuery()
      .in(_this || (this as any))
      .select(selector)
      .node((result) => (result ? resolve(result) : reject(result)))
      .exec()
  })
}

export function selectQuery(
  this: any,
  selector: string,
  fields: WechatMiniprogram.Fields,
  _this?: any
) {
  return new Promise<UniApp.NodeInfo & Recordable>((resolve, reject) => {
    uni
      .createSelectorQuery()
      .in(_this || (this as any))
      .select(selector)
      .fields(fields, (result) => (result ? resolve(result) : reject(result)))
      .exec()
  })
}
